package com.moon.config;

import com.moon.ws.WsHandler;
import com.moon.ws.WsInterceptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.socket.config.annotation.WebSocketConfigurer;
import org.springframework.web.socket.config.annotation.WebSocketHandlerRegistry;

@Configuration
public class WsConfig implements WebSocketConfigurer {
    @Autowired  //握手拦截器
    private WsInterceptor wsInterceptor;
    @Autowired  //消息处理器
    private WsHandler wsHandler;
    @Override
    public void registerWebSocketHandlers(WebSocketHandlerRegistry registry) {
                                                                                    //跨域
        registry.addHandler(wsHandler,"/myws").addInterceptors(wsInterceptor).setAllowedOrigins("*");
    }
}
